// pages/info/info.js
import { userBehavior } from '../../behaviors/userBehavior'
import {
  request
} from '../../utils/requestUtils';
Page({
  behaviors: [userBehavior],

  // 页面的初始数据
  data: {
    form:{}
  },
  onShow(){
    this.getTabBar().setData({
      active: 3
    })
    this.getStallInfo()
  },

  // 跳转到登录页面
  toLoginPage() {
    wx.navigateTo({
      url: '/pages/pre_index/index'
    })
  },
  onLoad(){
    
  },
  // 跳转商家详情页面
  myOrderList(){
    wx.navigateTo({
      url: '/pages/toMerchant/index'
    })
  },
    // 获取摊位信息
    async getStallInfo() {
      const result = await request({
        url: '/merchant/bus/stall/my',
        method: "POST",
        data: {}
      });
      if (result.data.code == 200) {
        this.setData({
          form: result.data.data
        })
        console.log('merchantAccount',this.data.form)
    
      }
    },
     // 切换状态
  async checkBusiness() {
    const modalRes = await wx.showModal({
      content: this.data.form.businessStatus == 2 ? '开始营业?' : '确定打烊？'
    })
    if (modalRes.cancel) return
    const result = await request({
      url: `/merchant/bus/stall`,
      method: "PUT",
      data:{
        id: this.data.form.id,
        businessStatus:this.data.form.businessStatus == 2 ? 1 : 2
      }
    })
    if (result.data.code == 200) {
      this.getStallInfo()
    }
  },
  // 条状今日订单列表
  toTodyOrderList(){
    wx.navigateTo({
      url: '/pages/merchant_my/todyOrderList/index',
    })
  },
    // 跳转订单统计
    toOrderReport(){
      wx.navigateTo({
        url: '/pages/merchant_report/index',
      })
    },
    // 跳转推荐设置
    toRecommend(){
      wx.navigateTo({
        url: '/pages/merchant_banner/index',
      })
    }
})
